package olegroshka.src.com.bofa.olegroshka.filter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFilter implements Filter<Date> {
	
	private static final String MM_DD_YYYY = "MM/dd/yyyy";
	private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(MM_DD_YYYY);
	
	final Date startDate;
	final Date endDate;
	
	public DateFilter(String startDate, String endDate) {
		try {
			this.startDate = DATE_FORMAT.parse(startDate);
			this.endDate = DATE_FORMAT.parse(endDate);
		} catch (ParseException e) {
			throw new IllegalArgumentException("Wrong date format, expected: " + MM_DD_YYYY, e);
		}
	}

	public DateFilter(Date startDate, Date endDate) {
		this.startDate = startDate;
		this.endDate = endDate;
	}

	public boolean accept(Date date) {
		return (date.after(startDate) && date.before(endDate)) || 
				date.equals(startDate) || 
				date.equals(endDate);
	}

}
